<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>添加学员</title>
    <script type="text/javascript" src="/js/jquery-1.11.1.js"></script>
    <script type="text/javascript" src="/js/bootstrap.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.css"></link>
    <link rel="stylesheet" type="text/css" href="/css/style.css"></link>
    <style>
        label span{color: #ff0000; padding-right: 5px;}
    </style>
</head>

<body>
<h2>添加学员</h2>
<form id="myForm" class="form-horizontal">
    <div class="form-group">
        <label class="col-sm-1 control-label"><span>*</span>姓名</label>
        <div class="col-sm-9">
            <input id="t1" required="required" name="stuname" class="form-control" placeholder="请输入姓名"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label"><span>*</span>学号</label>
        <div class="col-sm-9">
            <input id="t2" required="" name="stuno" class="form-control" placeholder="请输入学号"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label">所属联盟</label>
        <div class="col-sm-2">
            <select name="sex" class="form-control">
                <option value="-1">请选择性别</option>
                <option value="0">男</option>
                <option value="1">女</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label">电话</label>
        <div class="col-sm-9">
            <input name="phone" class="form-control" placeholder="请输入联系方式"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label">邮箱</label>
        <div class="col-sm-9">
            <input type="email" name="email" class="form-control" placeholder="请输入邮箱"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label">所属地区</label>
        <div class="col-sm-9">
            <input name="registered" class="form-control" placeholder="请输入所属地区"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label">专业</label>
        <div class="col-sm-2">
            <input name="profession" class="form-control" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label">政治身份</label>
        <div class="col-sm-2">
            <select name="politics" class="form-control">
                <option value="-1">请选择政治身份</option>
                <option value="群众">群众</option>
                <option value="团员">团员</option>
                <option value="党员">党员</option>

            </select>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-1 control-label"></label>
        <div class="col-sm-9">
            <button id="btnAdd" type="button" class="btn btn-sm btn-info">提&nbsp;交</button>
            <button type="reset"  class="btn btn-sm btn-warning">重&nbsp;置</button>
        </div>
    </div>
</form>
</body>
</html>
<script>
    $(function () {
        //提交按钮的单击事件
        $("#btnAdd").click(function () {
            var t1 = $("#t1").val()
            var t2 = $("#t2").val()

            if(t1.length<=0||t2.length<=0){
                alert("姓名和学号为必填项！")
                return
            }
            $.ajax({
                type: "POST",
                url: "/student/add/",
                data: $("#myForm").serialize(),
                dataType:"json",
                success: function(vo){
                    if(vo.code==200) {
                        alert("添加成功！")
                        window.location.href = "/pages/stu.html";

                    }else{
                        alert("添加失败！"+vo.msg);
                    }
                }
            });
        });
    });
</script>